
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>支付佣金</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
    <style>
        .layui-table-body .layui-table-cell {
            height: 75px; line-height: 75px;
        }
    </style>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-sm2 header-data">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span style="color: #999;font-size: 13px;">今日充值</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font">{$todayMoney}</p>

                </div>
            </div>
        </div>

        <div class="layui-col-sm2 header-data">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span style="color: #999;font-size: 13px;">昨日充值</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font">{$yesterdayMoney}</p>

                </div>
            </div>
        </div>
        <div class="layui-col-sm2 header-data">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span style="color: #999;font-size: 13px;">本月充值</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font">{$thisMonthMoney}</p>

                </div>
            </div>
        </div>

        <div class="layui-col-sm2 header-data">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span style="color: #999;font-size: 13px;">上月充值</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font">{$lastMonthMoney}</p>

                </div>
            </div>
        </div>

        <div class="layui-col-sm4 header-data">
            <div class="layui-card">
                <div class="layui-card-header">
                    <span style="color: #999;font-size: 13px;">全部充值</span>
                </div>
                <div class="layui-card-body layuiadmin-card-list">
                    <p class="layuiadmin-big-font">{$allMoney}</p>

                </div>
            </div>
        </div>

        <div class="layui-col-sm12">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-sm12">
                    <div class="layui-card">
                        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                            <div class="layui-form-item">

                                <div class="layui-inline">
                                    <input type="text" id="dayStart" name="start_date" placeholder="数据开始日期" autocomplete="off" class="layui-input">
                                </div>

                                <div class="layui-inline">
                                    <input type="text" id="dayEnd" name="end_date" placeholder="数据结束日期" autocomplete="off" class="layui-input">
                                </div>


                                <div class="layui-inline">
                                    <input type="text" name="agent_id" placeholder="代理Id" autocomplete="off" class="layui-input">
                                </div>

                                <div class="layui-inline">
                                    <input type="text" name="channel_id" placeholder="投放号Id" autocomplete="off" class="layui-input">
                                </div>


                                <div class="layui-inline">
                                    <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                                    </button>
                                </div>

                                <div class="layui-inline" style="float: right;">
                                    <button class="layui-btn layuiadmin-btn-role" data-type="add">添加</button>
                                </div>


                            </div>
                        </div>
                        <div class="layui-card-body">

                            <table id="LAY-user-back-role" lay-filter="LAY-user-back-role"></table>

                            <script type="text/html" id="table-useradmin-admin">
                                <a class="layui-btn layui-btn-primary layui-border-green layui-btn-xs" lay-event="contract" data-id="{{d.id}}">订单明细</a>
                            </script>


                            <script type="text/html" id="switchTpl">
                                <input type="checkbox" name="switch" lay-filter="switch" data-id="{{d.id}}" lay-skin="switch" lay-text="开|关"  {{ d.switch == 1 ? 'checked' : '' }}>
                            </script>

                            <script type="text/html" id="userTpl">
                                <div style="line-height: 40px;">
                                    <input type="radio" data-id="{{d.id}}" name="user_group_{{d.id}}" value="0" lay-filter="user_group" title="全部" {{#  if(d.user_group == 0){ }}checked{{#  } }}>
                                    <br>
                                    <input type="radio" data-id="{{d.id}}" name="user_group_{{d.id}}" value="1" lay-filter="user_group" title="已充值" {{#  if(d.user_group == 1){ }}checked{{#  } }}>
                                </div>
                            </script>

                            <script type="text/html" id="loginTpl">
                                <input type="checkbox" name="login_judg" lay-filter="login_judg" data-id="{{d.id}}" lay-skin="switch" lay-text="开|关"  {{ d.login_judg == 1 ? 'checked' : '' }}>
                            </script>

                            <script type="text/html" id="registerTpl">
                                <input type="checkbox" name="register_judg" lay-filter="register_judg" data-id="{{d.id}}" lay-skin="switch" lay-text="开|关"  {{ d.register_judg == 1 ? 'checked' : '' }}>
                            </script>


                        </div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>



<script src="/static/layuiadmin/layui/layui.js"></script>

<script>
    layui.config({
        base: '/static/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table
            ,admin = layui.admin;
        var util = layui.util;
        var laydate = layui.laydate;


        form.on('switch(switch)', function(data){
            var id = $(data.elem).data('id');
            if (data.elem.checked){
                var value = 1;
            }else {
                var value = 0;
            }
            admin.req({
                url: '/deduct/changeField'
                , type: "POST"
                , data: {'id': id, 'field': 'switch','value':value}
                , done: function (res) {
                    layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                        layer.closeAll();
                    });
                }, not_finish: function (res) {
                    layer.msg(res.msg);
                }
            });
        });

        form.on('switch(login_judg)', function(data){
            var id = $(data.elem).data('id');
            if (data.elem.checked){
                var value = 1;
            }else {
                var value = 0;
            }
            admin.req({
                url: '/deduct/changeField'
                , type: "POST"
                , data: {'id': id, 'field': 'login_judg','value':value}
                , done: function (res) {
                    layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                        layer.closeAll();
                    });
                }, not_finish: function (res) {
                    layer.msg(res.msg);
                }
            });
        });


        form.on('switch(register_judg)', function(data){
            var id = $(data.elem).data('id');
            if (data.elem.checked){
                var value = 1;
            }else {
                var value = 0;
            }
            admin.req({
                url: '/deduct/changeField'
                , type: "POST"
                , data: {'id': id, 'field': 'register_judg','value':value}
                , done: function (res) {
                    layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                        layer.closeAll();
                    });
                }, not_finish: function (res) {
                    layer.msg(res.msg);
                }
            });
        });


        form.on('radio(user_group)', function(data){
            console.log($(data.elem).data('id')); //得到radio原始DOM对象
            console.log(data.value); //被点击的radio的value值
            admin.req({
                url: '/deduct/changeField'
                , type: "POST"
                , data: {'id': $(data.elem).data('id'), 'field': 'user_group', 'value': data.value}
                , done: function (res) {
                    layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                        layer.closeAll();
                    });
                }, not_finish: function (res) {
                    layer.msg(res.msg);
                }
            });
        });


        //监听单元格编辑
        table.on('edit(LAY-user-back-role)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            var value = obj.value //得到修改后的值
                ,data = obj.data //得到所在行所有键值
                ,field = obj.field; //得到字段
            admin.req({
                url: '/deduct/changeField'
                , type: "POST"
                , data: {'id': obj.data.id, 'field': field, 'value': value}
                , done: function (res) {
                    layer.msg('设置成功', {icon: 1, time: 1000}, function () {
                        layer.closeAll();
                    });
                }, not_finish: function (res) {
                    layer.msg(res.msg);
                }
            });
        });

        var nowTime = new Date().valueOf();
        var start = laydate.render({
            elem: '#dayStart',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                endMax = end.config.max;
                end.config.min = date;
                end.config.min.month = date.month - 1;
            }
        });
        var end = laydate.render({
            elem: '#dayEnd',
            type: 'date',
            max: nowTime,
            done: function (value, date) {
                if ($.trim(value) == '') {
                    var curDate = new Date();
                    date = {
                        'date': curDate.getDate(),
                        'month': curDate.getMonth() + 1,
                        'year': curDate.getFullYear()
                    };
                }
                start.config.max = date;
                start.config.max.month = date.month - 1;
            }
        });

        //监听搜索
        form.on('submit(LAY-user-back-search)', function(data){
            var field = data.field;

            //执行重载
            table.reload('LAY-user-back-role', {
                where: field
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });

        table.render({
            elem: '#LAY-user-back-role'
            , url: '/deduct/configList' //模拟接口
            , page: true //开启分页
            ,even: true //开启隔行背景
            , limit: 20
            , cols: [[
                 {field: 'id', width: 80, title: 'ID'}
                , {field: 'agent_name', title: '代理',templet:function (d) {
                        if (d.agent_name != ''){
                            return "【"+d.agent_id+"】"+d.agent_name;
                        }else {
                            return  "【"+d.agent_id+"】";
                        }
                    },minWidth: 150}
                , {field: 'channel_name', title: '投放号',templet:function (d) {
                        if (d.channel_name != ''){
                            return "【"+d.channel_id+"】"+d.channel_name;
                        }else {
                            return  "【"+d.channel_id+"】";
                        }
                    },minWidth: 150}
                , {field: 'switch', title: '扣量总开关', templet: '#switchTpl',align: 'center'}
                , {field: 'odds', title: '扣量比例', edit: 'text'}
                , {field: 'money', title: '总充值金额',align: 'center',minWidth: 150,sort: true}
                , {field: 'dateMoney', title: '日期范围内金额',align: 'center',minWidth: 150}

                , {field: 'user_group', title: '用户群体', templet: '#userTpl'}

                , {field: 'register_day', title: '满注册天数',align: 'center', edit: 'text'}
                , {title: '注册判断', templet: '#registerTpl',align: 'center'}
                , {field: 'login_hour', title: '未登录小时',align: 'center', edit: 'text'}
                , {title: '登录判断', templet: '#loginTpl',align: 'center'}
                , {field: 'create_time', title: '创建时间'}
                , {field: 'update_time', title: '修改时间'}
            ]]
        });


        //触发排序事件
        table.on('sort(LAY-user-back-role)', function(obj){
            table.reload('LAY-user-back-role', {
                initSort: obj //记录初始排序，如果不设的话，将无法标记表头的排序状态。
                ,where: { //请求参数（注意：这里面的参数可任意定义，并非下面固定的格式）
                    order: obj.field + ' ' + obj.type //排序方式
                }
                ,page: {
                    curr: 1  // 将页码重置为第一页
                }
            });
        });


        //事件
        var active = {
            add: function(){
                layer.open({
                    type: 2
                    ,title: '添加扣量规则'
                    ,content: '/deduct/addRule.html'
                    ,offset: '5px'
                    , area: ['500px', '600px']
                    , maxmin: true//开启最大化最小化按钮
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submit = layero.find('iframe').contents().find("#LAY-user-role-submit");

                        //监听提交
                        iframeWindow.layui.form.on('submit(LAY-user-role-submit)', function(data){
                            var field = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            //$.ajax({});
                            admin.req({
                                url: '/deduct/addRule'
                                , type: "POST"
                                , data: field
                                , done: function (res) {
                                    layer.msg('添加成功', {icon: 1, time: 1000}, function () {
                                        table.reload('LAY-user-back-role');
                                        layer.close(index); //关闭弹层
                                    });
                                },not_finish:function (res) {
                                    layer.msg(res.msg);
                                }
                            });
                        });

                        submit.trigger('click');
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-role').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>
</body>

</html>

